<!-- meta page description: Support for landscape index calculations on raster -->
<h2>DESCRIPTION</h2>

This documentation is focused on scientists and developers who wants to
implement a new landscape index computation. Refer to the
<a href="r.li.html">r.li</a> modules overview and
<a href="g.gui.rlisetup.html">g.gui.rlisetup</a> module for user-focused
documentation.

<p>
<!--
TODO: make this clear and rename daemon to library since it is library and not a daemon
TODO: here can be just a really short intro and instructions how to get doxygen doc
-->
<em>r.li.daemon</em> provides support for landscape index calculations on raster
maps. It hides the management of areas, defined using <a href="g.gui.rlisetup.html">g.gui.rlisetup</a>
command. It is not used like a standalone program, but its functions are 
a library used by all <em>r.li.[index]</em> commands.<br>
This description is a tutorial for new index definition. <br><br>
The developer has only to focus on a unique area, like in mathematical definitions, and
has to write a C implementation of it.<br>
The areas are defined using a <em>struct</em> called <b>area_des</b> and it members are
explained in the source code (doxygen) documentation.
<p>
To write a new index only two steps are needed: 
<ol>
	<li>
	Define a function and insert its declaration on file <b>index.h</b> in <em>r.li.daemon</em>
	folder, which contains all index declarations. This function must be of this kind:
	<div class="code"><pre>
        int index(int fd, char ** par, area_des ad, double * result)
	</pre></div>
	where: <ul>
			<li><i>fd</i> is the raster map descriptor
			<li><i>par</i> is a matrix for special parameter (like argv in main)
			<li><i>ad</i> is the area descriptor 
			<li><i>result</i> is where to put the index calculation result
		</ul>
	This function has to return 1 on success and 0 otherwise.
    This function type is defined using typedef named <code>rli_func</code>.
	<li>
	Create a main for command line arguments parsing, and call the function
	<div class="code"><pre>
        int calculateIndex(char *file, rli_func *f,
                           char **parameters, char *raster, char *output);
	</pre></div>
	from the <i>r.li</i> library, for starting raster analysis.<br>
	It follows the meaning of parameters:
	<ul>
	<li><i>file</i> name of configuration file created using <a href="g.gui.rlisetup.html">g.gui.rlisetup</a>
	<li><i>f</i> pointer to index function defined above
	<li><i>parameters</i> pointer to index special parameters
	<li><i>raster</i> name of raster to use
	<li><i>output</i> output file name
	</ul>
</ol>
Compile it using a changed Makefile based on the file for <em>r.li.patchdensity</em>.

<p>
Refer to the <i>r.li</i> library documentation in the source code and
implementation of <i>r.li</i> modules for details and examples.

<h2>NOTES</h2>

Using GRASS library function to access raster rows can slow down moving windows 
execution. It is recommended to use 
<br><div class="code"><pre>
RLI_get_cell_row(int, int, area_des)
RLI_get_fcell_row(int, int, area_des)
RLI_get_dcell_row(int, int, area_des)
</pre></div><br>
to use an ad hoc build memory management developed to speed up the system.
The documentation is in doxygen files.


<h2>SEE ALSO</h2>

<em><a href="https://grass.osgeo.org/gdp/landscape/r_le_manual5.pdf">old r.le manual</a></em><br>
<em><a href="r.li.html">r.li</a></em> - package overview <br>
<em><a href="g.gui.rlisetup.html">g.gui.rlisetup</a></em>


<h2>REFERENCES</h2>
McGarigal, K., and B. J. Marks. 1995. FRAGSTATS: spatial pattern
analysis program for quantifying landscape structure. USDA For. Serv.
Gen. Tech. Rep. PNW-351. (<a href="http://treesearch.fs.fed.us/pubs/3064">PDF</a>)

<h2>AUTHORS</h2>

Claudio Porta and Lucio Davide Spano, students of Computer Science 
University of Pisa (Italy).<br>
Commission from Faunalia Pontedera (PI)<br>
Rewritten from "r.le.setup" by William L. Baker<br>
Various bug fixes by Markus Metz<br>
This program is free software under the GPL (>=v2)
Read the COPYING file that comes with GRASS for details.

<!--
<p>
<i>Last changed: $Date$</i>
-->
